package com.apes.fn.scm.merchant.account.repository;

import com.apes.fn.scm.merchant.account.model.MerchantFixedLoss;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author pengyb
 */
public interface MerchantFixedLossRepository extends CustomRepository<MerchantFixedLoss, String> {

    @Query(value = "SELECT TO_CHAR(T.bookkeepingDate,'yyyy-mm-dd') as bookkeepingDate,T.dept.name as deptName,T.carLicense as carLicense," +
            "T.source as source,T.sourceBusinessType as sourceBusinessType,T.remark as remark," +
            "T.paymentAmount as paymentAmount,T.platformAmount as platformAmount,T.adjustmentAmount as adjustmentAmount," +
            "T.storeAmount as storeAmount,T.collectionAmount as collectionAmount" +
            " FROM MerchantFixedLoss T where T.company.id=:company and " +
            "T.bookkeepingDate >=:reconcileBeginDate and T.bookkeepingDate < :reconcileEndDate ")
    List<Map<String, String>> findCompanyDetail(String company, Date reconcileBeginDate, Date reconcileEndDate);


    @Query(value = "SELECT T FROM MerchantFixedLoss T where T.company.id=:company and " +
            "T.bookkeepingDate >=to_date(:reconcileBeginDate,'yyyy-mm-dd') and T.bookkeepingDate < to_date(:reconcileEndDate,'yyyy-mm-dd')+1 ")
    List<MerchantFixedLoss> findCompany(String company, String reconcileBeginDate,String reconcileEndDate);

}
